#define _CRT_SECURE_NO_WARNINGS
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>

int my_atoi(const char* str)
{
	assert(str);
	int ret = 0;
	int negative = 1;
	while (isspace(*str))
		str++;
	if (*str == '-')
		negative = -1, ++str;
	while (*str)
	{
		if (*str >= '0' && *str <= '9')
		{
			ret = ret * 10 + (*str - '0');
			++str;
		}
		else
			return ret* negative;
	}
	return ret* negative;
}

int main()
{
	char s[] = "c1949e";
	char s1[] = " \t1949e";
	char s2[] = "-19r49";
	printf("%d\n", atoi(s));
	printf("%d\n", atoi(s1));
	printf("%d\n", atoi(s2));

	printf("%d\n", my_atoi(s));
	printf("%d\n", my_atoi(s1));
	printf("%d\n", my_atoi(s2));
	return 0;
}